using System.Collections.Generic;
using System.Xml;
using MbUnit.Framework;
using XmlObjects;
using XmlObjects.XmlWriter;

namespace XmlImportUnitTests
{
	[TestFixture]
	public class TestWriteXml
	{

		[Test]
		public void TestOne()
		{
			Simple simple = new Simple("coolio", "niceness", 12);
			simple.MySimples.Add(new Simple("sweet", "dope", 34));
			simple.MySimples.Add(new Complicated("sweet", "dope", 34));
			simple.MySimples.Add(new Simple("sweet", "dope", 34));
			IXmlWriter writer = XmlWriterFactory.GetWriter(typeof (Simple));

			simple.MySimple = new Complicated("nide", "f", 45);
			
			XmlDocument document = new XmlDocument();
			XmlElement element = document.CreateElement("coolbrain");
			XmlNode node = document.AppendChild(element);
			writer.Append(simple, node);
			document.Save("coolio.xml");
		}

		public class Complicated : Simple
		{
			public Complicated(string coolio, string nide, int cool) : base(coolio, nide, cool)
			{
			}

			private string foobar = "4444";
			[Attrib("Nice")]
			public string Foobar
			{
				get { return foobar; }
				set { foobar = value; }
			}
		}

		[Serializeable("simple")]
		public class Simple
		{
			private string coolio;
			List<int> integers = new List<int>();
			List<string> strings = new List<string>();

			private Simple mySimple;

			List<Simple> mySimples = new List<Simple>();

			[Property("mySimples/*")]
			[SubType("mySimple", typeof(Simple), true)]
			[SubType("complicated", typeof(Complicated))]
			public List<Simple> MySimples
			{
				get { return mySimples; }
				set { mySimples = value; }
			}

			public List<int> Integers
			{
				get { return integers; }
				set { integers = value; }
			}

			public List<string> Strings
			{
				get { return strings; }
				set { strings = value; }
			}

			[Property("mightBeComplicated")]
			[SubType("mySimple", typeof(Simple), true)]
			[SubType("complicated", typeof(Complicated))]
			public Simple MySimple
			{
				get { return mySimple; }
				set { mySimple = value; }
			}

			public Simple(string coolio, string nide, int cool)
			{
				this.coolio = coolio;
				this.nide = nide;
				this.cool = cool;

				for(int i=0; i<cool; i++)
				{
					integers.Add(i+cool);
					strings.Add(string.Format("!@#${0}$#@!", i + cool));
				}
			}

			private string nide;

			[Attrib("nide")]
			public string Nide
			{
				get { return nide; }
				set { nide = value; }
			}

			private decimal cool;
			[Attrib("cool")]
			public decimal Cool
			{
				get { return cool; }
				set { cool = value; }
			}

			[Property("coolio")]
			public string Coolio
			{
				get { return coolio; }
				set { coolio = value; }
			}
		}

	}
}